package cn.jwheel.log;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class LoggerFactory {

    /** 日志框架名，用于打印当前所用日志框架 */
    private String name;

    /** 日志对象缓存 */
    private Map<Object, Log> logCache;

    public LoggerFactory(String name){
        this.name = name;
        logCache = new ConcurrentHashMap<>();
    }

    /**
     * 获取日志框架名，用于打印当前所用日志框架
     */
    public String getName() {
        return this.name;
    }

    /**
     * 获得日志对象
     *
     * @param clazz 日志对应类
     * @return 日志对象
     */
    public Log getLog(Class<?> clazz) {
        Log log = logCache.get(clazz);
        if (null == log) {
            log = createLog(clazz);
            logCache.put(clazz, log);
        }
        return log;
    }

    public abstract Log createLog(Class<?> clazz);


    public LoggerFactory createLogFactory(){

        // TODO:扫描所有子类然后构建？

        return null;
    }

}
